package com.ruoyi.energize.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.energize.service.ICashOrderGoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.energize.domain.YancaoCategorySaleReport;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 烟草分类占比报告Controller
 *
 * @author ruoyi
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/energize/categorySaleReport")
public class YancaoCategorySaleReportController extends BaseController
{
    @Autowired
    private ICashOrderGoodsService cashOrderGoodsService;
    /**
     * 查询烟草分类占比报告列表
     */
    @PreAuthorize("@ss.hasPermi('energize:categorySaleReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(YancaoCategorySaleReport yancaoCategorySaleReport)
    {
        startPage();
        List<YancaoCategorySaleReport> list =new ArrayList<>();

        if(yancaoCategorySaleReport.getParams().get("beginOrderTime")!=null && yancaoCategorySaleReport.getParams().get("beginOrderTime")!="" &&
                yancaoCategorySaleReport.getParams().get("endOrderTime")!=null && yancaoCategorySaleReport.getParams().get("endOrderTime")!=""
        ){

           list = cashOrderGoodsService.selectYancaoCategorySaleReportList(yancaoCategorySaleReport);
        }
        return getDataTable(list);
    }

    /**
     * 导出烟草分类占比报告列表
     */
    @PreAuthorize("@ss.hasPermi('energize:categorySaleReport:export')")
    @Log(title = "烟草分类占比报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YancaoCategorySaleReport yancaoCategorySaleReport)
    {
        List<YancaoCategorySaleReport> list =new ArrayList<>();

        if(yancaoCategorySaleReport.getParams().get("beginOrderTime")!=null && yancaoCategorySaleReport.getParams().get("beginOrderTime")!="" &&
                yancaoCategorySaleReport.getParams().get("endOrderTime")!=null && yancaoCategorySaleReport.getParams().get("endOrderTime")!=""
        ){

            list = cashOrderGoodsService.selectYancaoCategorySaleReportList(yancaoCategorySaleReport);
        }
        ExcelUtil<YancaoCategorySaleReport> util = new ExcelUtil<YancaoCategorySaleReport>(YancaoCategorySaleReport.class);
        util.exportExcel(response, list, "烟草分类占比报告数据");
    }

}
